<?php
$baseUrl = Yii::app()->request->baseUrl;
$cs = Yii::app()->getClientScript();

$this->breadcrumbs = array(
    'Products'
);


$this->menu = array(
    array('label' => 'Thêm mới', 'url' => array('create')),
    array('label'=>Yii::t('main', 'Product Brand Admin'), 'url'=>array('/admin/productBrand/admin')),
    array('label'=>Yii::t('main', 'Product Quantity Admin'), 'url'=>array('/admin/product/quantityAdmin'))
);

/*
Yii::app()->clientScript->registerScript('create', "
$('.create-button').click(function(){
	$('.create-form').toggle();
	return false;
});
$('.search-form form').submit(function(){
	$('#product-grid').yiiGridView('update', {
		data: $(this).serialize()
	});
	return false;
});
");
 * 
 */
?>

<?php //echo CHtml::link('Thêm mới', '#', array('class' => 'create-button')); ?>
<div class="create-form" style="display:none">
    <?php
    /*
    $this->renderPartial('_form', array(
        'model' => $model,
        'listData' => $listData
    ));*/
    ?>
</div>
<?php
$form = $this->beginWidget('CActiveForm', array(
    'enableAjaxValidation' => TRUE,
        ));
?>
<?php
$this->widget('zii.widgets.grid.CGridView', array(
    'id' => 'product-grid',
    'dataProvider' => $model->search(),
    'filter' => $model,
    'columns' => array(
        /*
        array(
            'id' => 'autoId',
            'class' => 'CCheckBoxColumn',
            'selectableRows' => '50',
        ),*/
        array(
            'header'=>'',
            'value'=>'$this->grid->dataProvider->pagination->currentPage * $this->grid->dataProvider->pagination->pageSize + ($row+1)'
        ),
        array(
            'name' => 'avatar',
            'value' => '"<img src=\"".($data->avatar?Yii::app()->baseUrl."/".$data->avatar->url:"")."\" width=\"50\" height=\"50\"/>"',
            'type' => 'raw',
            'filter' => FALSE,
            'sortable' => FALSE,
        ),
        array(
            'name' => 'categoryId',
            'value' => 'isset($data->category)?$data->category->name:""',
            'filter' => CHtml::activeDropDownList($model, 'categoryId', $listData),
        ),
        array(
            'name' => 'name',
            'value' => '$data->name',
            'type' => 'raw',
        ),    
        array(
            'name'=>'code'
        ),
        array(
            'name' => 'brandId',
            'value' => '$data->brandId?$data->brand->name:""',
            'filter' => CHtml::activeDropDownList($model, 'brandId', ProductBrand::model()->getListIdName()),
        ),
        array(
            'name' => 'origin',
            'value' => '$data->origin',
            'type' => 'raw',
        ),
        array(
            'name' => 'price',
            'value' => '$data->price . "/" . $data->priceUnit',
            'type' => 'raw',
            'htmlOptions' => array("width" => "50px"),
        ),
        array(
            'name'=>'quantity'
        ),
        array(
            'name' => 'status',
            'value' => '$data->status==1?"Hiện":"Ẩn"',
            'filter' => array(1 => 'Hiện', 0 => 'Ẩn'),
        ),
        array(
            'class' => 'CButtonColumn',
        ),
    ),
));
?>
<script>
    function reloadGrid(data) {
        $.fn.yiiGridView.update('product-grid');
    }
</script>

<?php $this->endWidget(); ?>

<style>
    #preview {
        position: absolute;
        border: 1px solid #ccc;
        background: #333;
        padding: 5px;
        display: none;
        color: #fff;
    }

    #preview img {
        max-width: 500px;
        max-height: 500px;
    }
</style>